<!--
 * @Author: wangwang 2723008256@qq.com
 * @Date: 2022-05-19 09:38:35
 * @LastEditors: wangwang 2723008256@qq.com
 * @LastEditTime: 2022-09-20 15:36:45
 * @FilePath: \jzjypc4.0\src\views\HellpCenter\feedBack.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div id="container">
    <div class="bread">
      <span>当前位置：</span>
      <el-breadcrumb separator=">">
        <el-breadcrumb-item :to="{ path: '/personal' }"
          >个人中心</el-breadcrumb-item
        >
        <el-breadcrumb-item :to="{ path: '/personal/Custom' }"
          >客服</el-breadcrumb-item
        >
        <el-breadcrumb-item>帮助中心</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="content">
      <div class="top">
        <span></span>
        <h3>意见反馈</h3>
      </div>
      <div class="chose">
        <p>问题类型：</p>
        <el-radio-group v-model="radio">
          <el-radio-button
            :label="item.id"
            v-for="item in fkList"
            :key="item.id"
            >{{ item.title }}</el-radio-button
          >
        </el-radio-group>
      </div>
      <div class="miaoshu">
        <p>描述内容：</p>
        <!-- <textarea
          v-model="miaoshuValue"
          maxlength="300"
          id=""
          cols="90"
          rows="10"
          placeholder="请在这里简单描述一下您遇到问题内容（300字以内）"
        ></textarea> -->
        <el-input
          type="textarea"
          placeholder="请在这里简单描述一下您遇到问题内容（300字以内）"
          v-model="miaoshuValue"
          maxlength="300"
          show-word-limit
        >
        </el-input>
      </div>
      <div class="upImg">
        <div class="title">
          <p>上传照片:</p>
          <span>（最多可上传3张）</span>
        </div>
        <!-- 上传修改图片 -->
        <div class="picList">
          <div class="pic" v-for="item in picList" :key="item.file_url">
            <img :src="item.file_url" />
          </div>
          <div class="upPics">
            <div type="ghost" @click="zh_uploadFile">
              <i class="el-icon-plus"></i>
            </div>
            <input
              type="file"
              ref="evfile"
              @change="zh_uploadFile_change"
              style="display: none"
            />
          </div>
        </div>
        <!-- <el-dialog :visible.sync="dialogVisible">
          <img width="100%" height="100%" :src="dialogImageUrl" alt="" />
        </el-dialog> -->
      </div>
      <div class="tel">
        <p>联系方式：</p>
        <input
          placeholder="为及时向您反馈回复信息，希望留下您的联系方式~"
          v-model="lianxiValue"
          width="200px"
        />
      </div>
      <button @click="subMit">提交反馈</button>
    </div>
  </div>
</template>

<script>
import { qiniuconfig, list_systypes, create_yjfk } from "../../api/http";
import * as qiniu from "qiniu-js";
import { timeStamp2String } from "../../utils/time";
export default {
  data() {
    return {
      fkList: [], //反馈分类
      radio: "",
      textarea: "",
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      limitNum: 0,
      noupdate: true,
      miaoshuValue: "", //描述内容
      lianxiValue: "", //联系方式内容
      baseurl: "", //七牛云域名
      upload_path: "", //七牛云上传目录
      picList: [],
    };
  },
  created() {
    // 回到顶部
    $(document).ready(function () {
      $(window).scrollTop(0);
    });

    
    list_systypes({
      md5key: localStorage.getItem("md5key"),
      type_str: "yjfktype",
    }).then((res) => {
      if (res.retInt == 1) {
        console.log(res, "反馈分类");
        this.fkList = res.retRes;
      }
    });
  },
  methods: {
    //上传图片相关
    zh_uploadFile() {
      this.$refs.evfile.click();
    },
    zh_uploadFile_change(evfile) {
      console.log(evfile);
      //file是选择的文件对象
      return new Promise((resolve, reject) => {
        qiniuconfig({
          md5key: localStorage.getItem("md5key"),
        }).then((res) => {
          //获取后台返的token  和域名
          this.baseurl = res.retRes.file_base;
          this.upload_path = res.retRes.upload_path;
          let uptoken = res.retRes.qiniu_token;
          let file = evfile.target.files[0];
          let key =
            this.upload_path +
            timeStamp2String(new Date().getTime(), 12) +
            "/" +
            new Date().getTime() +
            Math.floor(Math.random() * 1000) +
            file.name.substring(file.name.lastIndexOf("."), file.name.length); //这是上船后返回的文件名，这里为了避免重复，加上了时间戳和随机数
          var config = {
            useCdnDomain: true, //表示是否使用 cdn 加速域名，为布尔值，true 表示使用，默认为 false。
            // region: qiniu.region.z0, //选择上传域名区域；当为 null 或 undefined 时，自动分析上传域名区域。
            domain: "https://static.idianjiao.com", //配置好的七牛云域名
            chunkSize: 100, //每个分片的大小，单位mb，默认值3
            forceDirect: true, //直传还是断点续传方式，true为直传
          };
          var putExtra = {
            fname: file.name, //文件原始文件名
            params: {},
            mimeType: [] || null,
          };
          var observable = qiniu.upload(file, key, uptoken, putExtra, config);
          observable.subscribe({
            next: (result) => {
              //主要用来展示进度
            },
            error: (err) => {
              //上传错误后触发
              console.log(err);
              reject(err);
            },
            complete: (result) => {
              //上传成功后触发。包含文件地址。
              console.log(file.name, "ahah");
              console.log(this.baseurl + "/" + result.key, "aheihei");
              this.file_url = this.baseurl + "/" + result.key;
              this.picList.push({ name: file.name, file_url: this.file_url });
              const upPics = document.getElementsByClassName("upPics")[0];
              if (this.picList.length >= 3) {
                upPics.style.display = "none";
              } else {
                upPics.style.display = "block";
              }
              resolve(result);
            },
          });
        });
      });
    },
    //提交
    subMit() {
      console.log(
        this.radio,
        this.picList,
        this.miaoshuValue,
        this.lianxiValue
      );
      if (this.radio == "") {
        this.$message({
          message: "请选择问题类型",
          duration: 2000,
          offset: 300,
        });
      } else if (this.miaoshuValue == "") {
        this.$message({
          message: "请添加问题描述",
          duration: 2000,
          offset: 300,
        });
      } else if (this.lianxiValue == "") {
        this.$message({
          message: "请填写联系方式",
          duration: 2000,
          offset: 300,
        });
      } else {
        create_yjfk({
          md5key: localStorage.getItem("md5key"),
          yjfktype_id: this.radio,
          contents: this.miaoshuValue,
          phone: this.lianxiValue,
          file_urls: this.picList,
        }).then((res) => {
          if (res.retInt == 1) {
            console.log(res, "提交结果");
            this.$message({
              message: "感谢您提出的宝贵意见！",
              duration: 3000,
              offset: 300,
            });
            setTimeout(() => {
              this.$router.go(-1);
            }, 3000);
          }
        });
      }
    },
  },
};
</script>
<style>
/* 面包屑 */
.el-breadcrumb__inner a,
.el-breadcrumb__inner.is-link:hover {
  color: #08a579;
}
.el-breadcrumb__inner a,
.el-breadcrumb__inner.is-link {
  font-weight: normal;
  color: #626366;
}
.el-breadcrumb__separator {
  color: #626366;
}
.el-textarea__inner {
  /* border:1px solid #08a579 */
}
.el-textarea__inner {
  width: 800px;
  border:1px solid #08a579 !important
}
.el-upload--picture-card:hover {
  border-color: #08a579;
}
.hide .el-upload--picture-card {
  display: none;
}
</style>
<style lang="less" scoped>
#container {
  height: 100%;
  background-color: #f0f0f5;
  overflow: hidden;
  .bread {
    display: flex;
    margin: 10px auto;
    width: 1200px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #626366;
    line-height: 24px;
    .el-breadcrumb {
      font-size: 14px;
      line-height: 24px;
      /deep/.el-breadcrumb__item:last-child {
        .el-breadcrumb__inner {
          color: #08a579;
        }
      }
    }
  }
  .content {
    // display: flex;
    width: 1200px;
    // height: 100%;
    margin: 0 auto;
    background-color: #fff;
    overflow: hidden;
    .top {
      display: flex;
      margin: 30px 0px 40px 30px;
      span {
        display: inline-block;
        position: relative;
        top: 5px;
        margin-right: 10px;
        width: 3px;
        height: 20px;
        background: #08a579;
        border-radius: 2px;
      }
      h3 {
        font-size: 20px;
      }
    }
    /deep/.el-radio-button {
      margin-right: 20px;
      user-select: none;
    }
    /deep/.el-radio-button__inner {
      width: 100px;
      height: 32px;
      border: 1px solid #dee0e3;
      border-radius: 16px;
      box-shadow: none;
    }
    /deep/.el-radio-button__orig-radio:checked + .el-radio-button__inner {
      background-color: #f0faf7;
      color: #0ca67b;
      border: 1px solid #08a579;
    }
    /deep/.el-radio-button__inner:hover {
      color: #0ca67b;
    }
    .chose {
      margin-left: 30px;
      margin-bottom: 30px;
      p {
        margin-bottom: 20px;
        font-size: 14px;
        color: #646566;
        line-height: 34px;
      }
    }
    .miaoshu {
      margin-left: 30px;
      p {
        margin-bottom: 20px;
        font-size: 14px;
        color: #646566;
        line-height: 34px;
      }
      textarea {
        padding: 6px;
        width: 840px;
        height: 160px;
        border: 0;
        outline: none;
        border: 1px solid #ccc;
        border-radius: 5px;
        color: #333;
      }
    }
    .upImg {
      margin-left: 30px;
      .title {
        display: flex;
        margin: 30px 0 20px 0;
        p {
          font-size: 14px;
          color: #646566;
        }
        span {
          font-size: 12px;
          color: #969799;
        }
      }
      .picList {
        display: flex;
        .pic {
          position: relative;
          width: 160px;
          height: 160px;
          img {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translateX(-50%) translateY(-50%);
            margin-right: 10px;
            max-width: 160px;
            max-height: 160px;
          }
        }
        .upPics {
          position: relative;
          width: 160px;
          height: 160px;
          border: 1px dashed #ccc;
          cursor: pointer;
          i {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translateX(-50%) translateY(-50%);
            padding: 68px;
            font-size: 24px;
            color: #ccc;
          }
        }
      }
    }
    .tel {
      margin: 30px 0 40px 30px;
      p {
        margin-bottom: 20px;
        font-size: 14px;
        color: #646566;
        line-height: 34px;
      }
      input {
        padding-left: 20px;
        width: 780px;
        height: 40px;
        outline: none;
        border: 0;
        border: 1px solid #08a579;
        border-radius: 8px;
        color: #333;
      }
    }
    button {
      position: relative;
      left: 780px;
      margin-bottom: 30px;
      width: 120px;
      height: 40px;
      background: #08a579;
      border-radius: 4px;
      border: 0;
      color: #fff;
      cursor: pointer;
    }
  }
}
</style>
